﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SemiCASE.Business;

public partial class PopUp_ProjectWorkItems : System.Web.UI.Page
{
    private string ProjectID
    {
        get
        {
            return Request.QueryString["ProjectID"] != null ? Request.QueryString["ProjectID"] : String.Empty;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Load();
            ProjectName(this.ProjectID);
        }
    }

    private void ProjectName(string projectID)
    {
        if (Session["ProjectList"] != null)
        {
            DataTable dt = (DataTable)Session["ProjectList"];
            foreach (DataRow row in dt.Rows)
            {
                if (row["ProjectID"].ToString() == projectID)
                {
                    LabelProjectName.Text = row["Name"].ToString();
                    break;
                }
            }
        }
    }

    private void Load()
    {
        DataTable dt = new WorkItemBS().LoadProjectWorkItemFromDB(new Guid(this.ProjectID));

        if (dt.Rows.Count > 0)
        {
            gvWorkItem.DataSource = dt;
            gvWorkItem.DataBind();
        }
        else
        {
            gvWorkItem.DataSource = null;
            gvWorkItem.DataBind();
        }
    }
}